package com.yonyou.ucf.mdf.app.isvdxq.ReturnResult;

import java.util.Date;
import java.util.List;

/**
 * @功能 接口返回的数据实体类
 */
public class DataResult<T> {

    private int status;//状态 1成功
    private String message;//状态信息
    private Long time = new Date().getTime();
    private Object Info; //其它


    //数据体
    private T data;

    //数据体List
    private List<T> dataList;

    //分页信息
    private int pageNum; //获得当前页
    private int pageSize; //获得一页显示的条数
    private int currPageSize; //获得当前页返回的条数，可以小于pageSize
    private int totalPages; //获得总页数
    private int totalSize; //总条数

    private int orderAuditType; // 单据弃审状态

    public DataResult() {
    }

    public DataResult(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public DataResult(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public DataResult(int status, String message, List<T> dataList) {
        this.status = status;
        this.message = message;
        this.dataList = dataList;
    }

    public DataResult(int status, String message, List<T> dataList, int orderAuditType) {
        this.status = status;
        this.message = message;
        this.dataList = dataList;
        this.orderAuditType = orderAuditType;
    }

    public DataResult(int status, String message, List<T> dataList, int pageNum, int pageSize, int currPageSize, int totalPages, int totalSize) {
        this.status = status;
        this.message = message;
        this.dataList = dataList;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.currPageSize = currPageSize;
        this.totalPages = totalPages;
        this.totalSize = totalSize;
    }

    public Object getInfo() {
        return Info;
    }

    public void setInfo(Object info) {
        Info = info;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Long getTime() {
        return time;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrPageSize() {
        return currPageSize;
    }

    public void setCurrPageSize(int currPageSize) {
        this.currPageSize = currPageSize;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(int totalSize) {
        this.totalSize = totalSize;
    }

    public int getOrderAuditType() {
        return orderAuditType;
    }

    public void setOrderAuditType(int orderAuditType) {
        this.orderAuditType = orderAuditType;
    }

    /**
     * 根据页大小自动计算总页数
     * pageSize>0 有效
     *
     * @param totalSize
     */
    public void setTotalSizeEx(int totalSize) {
        this.totalSize = totalSize;
        if (this.pageSize > 0) {
            this.totalPages = (int) Math.ceil((double) totalSize / this.pageSize);
        }
    }

    public void setDataListEx(List<T> dataList) {
        this.dataList = dataList;
        this.currPageSize = dataList.size();
    }

    public void setPageParams(List<T> dataList, int totalSize){
        this.dataList = dataList;
        this.currPageSize = dataList.size();
        this.totalSize = totalSize;
        if (this.pageSize > 0) {
            this.totalPages = (int) Math.ceil((double) totalSize / this.pageSize);
        }
    }

    /**
     * 返回 startNumber
     * @return
     */
    public int initStartNumber() {
        int m = 0;
        if (this.pageNum > 1) m += (this.pageNum - 1) * this.pageSize;
        return m;
    }
}
